package com.shycloud.mido.common.core.exception;

import com.shycloud.mido.common.core.constant.CommonConstants;
import com.shycloud.mido.common.core.util.R;
import lombok.Getter;
import lombok.Setter;

/**
 * 全局业务异常
 *
 * @author nianhua.jiang
 * @date 2020/8/3
 */
public class BusinessException extends RuntimeException {

	private static final long serialVersionUID = 4868842805385777275L;

	/** 错误状态 */
	private Integer code;

	@Getter
	@Setter
	private Object data;

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public BusinessException() {
	}

	public BusinessException(String msg) {
		super(msg);
		this.code = CommonConstants.FAIL;
		this.data = false;
	}

	public BusinessException(Integer code, String msg) {
		super(msg);
		this.code = code;
	}

	public BusinessException(R status) {
		super(status.getMsg());
		this.code = status.getCode();
		this.data = status.getData();
	}

}
